package kr.saeildamil.androidstudy_second2930;

import kr.saeildamil.androidstudy_second.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class NapAlarm extends Activity {
	static final int NAPNOTI=1;
	NotificationManager mNotiManager;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch29_napalarm);
		mNotiManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
	}
	
	public void mOnClick(View v){
		Toast.makeText(NapAlarm.this, "안녕히 주무세요", 0).show();
		v.postDelayed(new Runnable() {
			@SuppressLint("NewApi")
			@Override
			public void run() {
				Intent intent=new Intent(NapAlarm.this, NapEnd.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				PendingIntent content=PendingIntent.getActivity(NapAlarm.this, 0, intent, 0);
				
				Notification.Builder noti=new Notification.Builder(NapAlarm.this);
				noti.setTicker("일어나세요");
				noti.setContentTitle("기상 시간");
				noti.setContentText("일어나! 일할 시간이야.");
				noti.setSubText("일을 해야 돈을 벌고 돈을 벌어야 밥먹고 살지!!");
				noti.setSmallIcon(R.drawable.mugung);
				noti.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.hangyul));
				noti.setContentIntent(content);
				noti.build();
				
				mNotiManager.notify(NAPNOTI, noti.getNotification());
			}
		}, 5000);
	}
}
